﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using V = Science.Mathematics.VectorCalculus;

namespace VectorCalculus5Ed.Chapter4.Section3
{
    public class Example05
    {
        public Example05()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
        public void Compute()
        {
            V.Function.ToLastType<double[], double[]> ff
                = new V.Function.ToLastType<double[], double[]>(grad);
            V.VectorField f = new V.VectorField(ff);
            double[] c = {1.0,1.0,1.0};
            V.Point p = new V.Point(c);
            f.FindComponents(p);
            result += f[0].ToString() + "\r\n";
            result += f[1].ToString() + "\r\n";
            result += f[2].ToString() + "\r\n";
        }
        private double[] grad(double[] x)
        {
            V.Function.ToLastType<double[], double> delv
                = new V.Function.ToLastType<double[], double>(v);
            V.Gradient gr = new V.Gradient(delv, x);
            gr.Compute();
            return gr.Result;
        }
        private double v(double[] x)
        {
            return -1.0 / Math.Sqrt(x[0]*x[0]+x[1]*x[1]+x[2]*x[2]);
        }
    }
}
/*
0.192450089730004
0.192450089730004
0.192450089730004
*/
